package com.ktgj.flight.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.ktgj.flight.domain.FlightOrderIternaryDTO;
import com.ktgj.flight.domain.vo.FlightOrderIternaryVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ktgj.common.log.annotation.Log;
import com.ktgj.common.log.enums.BusinessType;
import com.ktgj.common.security.annotation.PreAuthorize;
import com.ktgj.flight.domain.FlightOrderIternary;
import com.ktgj.flight.service.IFlightOrderIternaryService;
import com.ktgj.common.core.web.controller.BaseController;
import com.ktgj.common.core.web.domain.AjaxResult;
import com.ktgj.common.core.utils.poi.ExcelUtil;
import com.ktgj.common.core.web.page.TableDataInfo;

/**
 * 机票订单行程单Controller
 * 
 * @author ruoyi
 * @date 2022-01-12
 */
@RestController
@RequestMapping("/flightOrderIternary")
public class FlightOrderIternaryController extends BaseController
{
    @Autowired
    private IFlightOrderIternaryService flightOrderIternaryService;

    /**
     * 查询机票订单行程单列表
     */
    @PreAuthorize(hasPermi = "flight:iternary:list")
    @GetMapping("/list")
    public TableDataInfo list(FlightOrderIternary flightOrderIternary)
    {
        startPage();
        List<FlightOrderIternary> list = flightOrderIternaryService.selectFlightOrderIternaryList(flightOrderIternary);
        return getDataTable(list);
    }

    /**
     * 导出机票订单行程单列表
     */
    @PreAuthorize(hasPermi = "flight:iternary:export")
    @Log(title = "机票订单行程单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, FlightOrderIternary flightOrderIternary) throws IOException
    {
        List<FlightOrderIternary> list = flightOrderIternaryService.selectFlightOrderIternaryList(flightOrderIternary);
        ExcelUtil<FlightOrderIternary> util = new ExcelUtil<FlightOrderIternary>(FlightOrderIternary.class);
        util.exportExcel(response, list, "机票订单行程单数据");
    }

    /**
     * 获取机票订单行程单详细信息
     */
    @PreAuthorize(hasPermi = "flight:iternary:query")
    @GetMapping(value = "/{invoiceId}")
    public AjaxResult getInfo(@PathVariable("invoiceId") Long invoiceId)
    {
        return AjaxResult.success(flightOrderIternaryService.selectFlightOrderIternaryById(invoiceId));
    }

    /**
     * 新增机票订单行程单
     */
    //@PreAuthorize(hasPermi = "flight:iternary:add")
    //@Log(title = "机票订单行程单", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult add(HttpServletRequest request, @RequestBody FlightOrderIternary flightOrderIternary)
    {
        String token = request.getHeader("token");
        try {
            return toAjax(flightOrderIternaryService.insertFlightOrderIternary(token, flightOrderIternary));
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.error(e.getMessage());
        }
    }

    /**
     * 修改机票订单行程单
     */
    //@PreAuthorize(hasPermi = "flight:iternary:edit")
    @Log(title = "机票订单行程单", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    public AjaxResult edit(@RequestBody FlightOrderIternary flightOrderIternary)
    {
        return toAjax(flightOrderIternaryService.updateFlightOrderIternary(flightOrderIternary));
    }

    /**
     * 删除机票订单行程单
     */
    @PreAuthorize(hasPermi = "flight:iternary:remove")
    @Log(title = "机票订单行程单", businessType = BusinessType.DELETE)
	@DeleteMapping("/{invoiceIds}")
    public AjaxResult remove(@PathVariable Long[] invoiceIds)
    {
        return toAjax(flightOrderIternaryService.deleteFlightOrderIternaryByIds(invoiceIds));
    }

    /**
     * 行程单列表
     * @param iternary
     * @return
     */
    @PostMapping("/orderIternaryList")
    public TableDataInfo orderIternaryList(@RequestBody FlightOrderIternaryVO iternary) {
        startPage();
        List<FlightOrderIternaryDTO> iternaryDTOList = flightOrderIternaryService.orderIternaryList(iternary);
        return getDataTable(iternaryDTOList);
    }
}
